<@bolt.formTemplate path="code_generator" id="table_form_config" haveSubmitBtn="false" />

<table class="table table-striped" data-toggle="editTable" id="headConfigTable">
    <thead>
    <tr>
        <th>标题</th>
        <th>名称</th>
        <th>类型</th>
        <th>是否查询</th>
        <th>验证方法</th>
    </tr>
    </thead>
    <tbody>
    <tr>
        <td>
            <@bolt.text id="label" validate="*" validateMessage="请填写标题"/>
        </td>
        <td>
            <@bolt.text id="id" validate="*" validateMessage="请填写标题"/>
        </td>
        <td>
            <@bolt.select id="type" itemValue="list:text=文本|hidden=隐藏|select=下拉列表|lookup=查找输入|radio=单选框|check=多选"/>
        </td>
        <td>
            <@bolt.switchery id="queryField"/>
        </td>
        <td>
            <@bolt.select id="validator"  itemValue="list:''=空|*=必填|N=数值|E=邮件|D=日期|Z=整数" attribute="width=100"/>
        </td>
    </tr>
    </tbody>
</table>

<div class="pull-right" style="padding-top: 10px">
    <button type="button" class="btn btn-success" id="submitBtn"><i class="icon-ok"></i> 保存</button>
    <button type="button" class="btn cancelBtn" data-toggle="close_modal"><i class="icon-undo"></i> 取消</button>
</div>
<script type="application/javascript">
    $.namespace('Page.GeneratorForm');
    Page.GeneratorForm = function () {
        return {
            init: function () {

                $('#dbGridId').unbind('change').change(function () {
                    var that = $(this);
                    Page.GeneratorForm.getTableColumns(that.val());
                });

                $('#submitBtn').unbind('click').click(function () {
                    Page.GeneratorForm.formGenerator();
                })
                //Page.GeneratorForm.bindKey();
            },



            getTableColumns: function (tableId) {
                Bolt.ajax('doajax', {
                    data: {tableName: tableId},
                    url: '${base}/admin/sys/code_generator/findTableForForm',
                    loadingMask: true,
                    okCallback: function (data) {
                        $('#headConfigTable').editTable('load', data);
                    }
                });
            },
            formGenerator: function () {
                var data = {}, modulePath = $('#modulePath').val(),
                    moduleTitle = $('#moduleTitle').val(),
                    package=$('#package').val(),entity = $('#entity').val();
                data['modulePath'] = modulePath;
                data['moduleTitle'] = moduleTitle;
                data['entityName'] = package+"."+entity;

                var allData = $('#headConfigTable').editTable('allData');
                data['formItems'] = JSON.stringify(allData);
                Bolt.ajax('doajax', {
                    data: data,
                    url: '${base}/admin/sys/code_generator/formGenerator',
                    loadingMask: true,
                    okCallback: function (content) {
                        alert(content);
                        Page.FormGenerator.editor.setValue(content);
                       // Page.FormGenerator.formatCode();
                        Bolt.dialog('closeCurrent');
                    }
                })
            }
        }
    }();

    $(document).ready(function () {
        Page.GeneratorForm.init();
    });
</script>
